﻿<Window x:Class="SimpleChat.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
        xmlns:w="clr-namespace:System.Windows.Workarounds" 
        Title="{Binding Title}"
        DataContext="{Binding Main, Source={StaticResource Locator}}"
        Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="22" />
            <RowDefinition Height="*" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="75" />
        </Grid.ColumnDefinitions>
        
        <Menu Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3">
            <MenuItem Header="_Fichier">
                <MenuItem Header="_Connexion à un salon">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <cmd:EventToCommand Command="{Binding JoinServerCommand, Mode=OneWay}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </MenuItem>
                <MenuItem Header="_Héberger un salon">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <cmd:EventToCommand Command="{Binding CreateNewServerCommand, Mode=OneWay}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </MenuItem>
                <Separator />
                <MenuItem Header="_Quitter" />
            </MenuItem>
            <MenuItem Header="_?">
                <MenuItem Header="A Propos" />
            </MenuItem>
        </Menu>

        <ListBox Grid.Column="0" Grid.Row="1" ItemsSource="{Binding Users}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Username}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <ListBox Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding ChatMessages}" w:ListBox.AutoScroll="True"
                 ScrollViewer.HorizontalScrollBarVisibility="Hidden">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock TextWrapping="WrapWithOverflow">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="({0:HH\:mm}) - {1}">
                                <Binding Path="Date"></Binding>
                                <Binding Path="Message"></Binding>
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <TextBox Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" x:Name="MessageTextBox" Text="{Binding InputMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        <Button Grid.Column="2" Grid.Row="2" Content="Envoyer" Command="{Binding SendMessageCommand}" IsDefault="{Binding ElementName=MessageTextBox,
                                               Path=IsKeyboardFocused}" />
        
    </Grid>
</Window>
